from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone

SUBJECT_CHOICE = [
    ('语文', '语文'),
    ('数学', '数学'),
    ('英语', '英语'),
    ('物理', '物理'),
    ('化学', '化学'),
    ('政治', '政治'),
]

EXERCISE_CHOICE = [
    ('错', '错'),
    ('对', '对'),
    ('不会', '不会'),
]

QUESTION_TYPE = [
    ('问题', '问题'),
    ('概念', '概念'),
]


# 题目
class Question(models.Model):
    course = models.CharField(choices=SUBJECT_CHOICE, max_length=20)  # 学科
    question_type = models.CharField(max_length=50)
    subject = models.CharField(max_length=50, blank=True)  # 类型
    title = models.CharField(max_length=100)  # 标题
    question = models.CharField(max_length=100)
    question_txt = models.TextField(blank=True)
    answer = models.CharField(max_length=100, blank=True)
    answer_txt = models.TextField(blank=True)
    analyze = models.CharField(max_length=100, blank=True)
    analyze_txt = models.TextField(blank=True)


# 练习记录
class ExerciseRecord(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
    exercise_result = models.CharField(choices=EXERCISE_CHOICE, max_length=10)  # 练习结果
    cost = models.PositiveIntegerField()  # 耗费时间，秒
    mark = models.BooleanField(default=False)
    exercise_last = models.DateTimeField(default=timezone.now)


# 记忆检测
class TestRecord(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
    successes = models.IntegerField()  # 成功次数 0 <= successes <= total
    total = models.IntegerField()  # 总次数，1 <= total
    alpha = models.FloatField(default=3.)  # α，β， t
    beta = models.FloatField(default=3.)
    t = models.FloatField(default=24.)
    recall = models.IntegerField(default=0)
    last_test = models.DateTimeField(default=timezone.now)
    last_cal = models.DateTimeField(null=True)  # 最近计算


# 文档
class Doc(models.Model):
    course = models.CharField(max_length=10)
    title = models.CharField(max_length=200)
    brief = models.TextField(blank=True)
    bucket = models.CharField(max_length=100)
    filename = models.CharField(max_length=200)  # minio url
    created = models.DateTimeField(default=timezone.now)
